const enterpriseVue = new Vue({
  el: '#app',
  data() {
    //校验身份证号
    var checkIDCard = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('身份证号不能为空'));
      }
      setTimeout(() => {
        if (!ID_Validity(value)) {
          callback(new Error('请输入正确的身份证号'));
        }
      }, 100);
    }
    return {
      pickerOptions: pickerOptions,
      rules: {
        type: [{ required: true, message: '请选择会员类型', trigger: 'blur', }],
        Permissions: [{ required: true, message: '请选择会员权限', trigger: 'blur', }],
      },
      form: {
        Enterprise_Info_SerialNumber: "",
        Enterprise_Name: '',
        Industry_SubCategory_SerialNumber: '',
        Industry_Category_SerialNumber: '',
        Tax_Number: '',
        Row_Status: '',
        Operation_ID: '',
        Operation_Datetime: '',
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        Children: {
          enterprise_legal_person: [{
            Enterprise_Legal_Person_SerialNumber: "",
            Enterprise_Info_SerialNumber: '',
            Legal_Person: '',
            Mobile: '',
            ID_Number: '',
            Row_Status: '',
            Operation_ID: '',
            Operation_Datetime: '',
          }],
          enterprise_invoiceinfo: [{
            Enterprise_InvoiceInfo_SerialNumber: "",
            Enterprise_Info_SerialNumber: '',
            Address: '',
            Mobile: '',
            Bank_Name: '',
            Bank_Account: '',
            Row_Status: '',
            Operation_ID: '',
            Operation_Datetime: '',
          }],
        }
      },
      loading: false
    }
  },
  mounted() {

  },
  methods: {
    submitForm(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.loading = true
          $.ajax({
            url: '../addGeneralBusinessAction',
            type: 'POST',
            data: {
              Data: JSON.stringify({
                enterprise_info: [_this.form]
              }),
              token: $.cookie("token")
            },
            success: function (res) {
              if (res.Status === 'success') {
                _this.$message.success("提交成功")
                window.location.href = './JobCategory.html'
              } else {
                _this.$message.error("提交失败，请稍后再试")
              }
            },
            error: function () {
              _this.$message.error("操作失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }

      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    add_enterprise_legal_person() {
      this.form.Children.enterprise_legal_person.push({
        Enterprise_Legal_Person_SerialNumber: "",
        Enterprise_Info_SerialNumber: '',
        Legal_Person: '',
        Mobile: '',
        ID_Number: '',
        Row_Status: '',
        Operation_ID: '',
        Operation_Datetime: '',
      })
    },
    remove_enterprise_legal_person() {
      if (this.form.Children.enterprise_legal_person.length > 1) {
        this.form.Children.enterprise_legal_person.pop()
      } else {
        this.$message({
          message: '不能在删除了',
          type: 'warning'
        })
      }
    },
    add_enterprise_invoiceinfo() {
      this.form.Children.enterprise_invoiceinfo.push({
        Enterprise_InvoiceInfo_SerialNumber: "",
        Enterprise_Info_SerialNumber: '',
        Address: '',
        Mobile: '',
        Bank_Name: '',
        Bank_Account: '',
        Row_Status: '',
        Operation_ID: '',
        Operation_Datetime: '',
      })
    },
    remove_enterprise_invoiceinfo() {
      if (this.form.Children.enterprise_invoiceinfo.length > 1) {
        this.form.Children.enterprise_invoiceinfo.pop()
      } else {
        this.$message({
          message: '不能在删除了',
          type: 'warning'
        })
      }
    },
  }
})